package server_V2;
// <editor-fold defaultstate="collapsed" desc="Imports">
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import lib.StreamSocket;

// </editor-fold> 

/**
 * @file ServerDataTransferThread.java
 *
 * @version 0.1
 * @author Chris Sewell 10008342
 */
public class ServerDataTransferThread extends Thread {
    // <editor-fold defaultstate="collapsed" desc="Attributes">

    StreamSocket clientFileStream;
    byte[] data;
    int length;
    // </editor-fold> 
    // <editor-fold defaultstate="collapsed" desc="Constructors">

    public ServerDataTransferThread(byte[] data, int length, StreamSocket clientFileStream) throws IOException {
        //Prepare stream and data for transfer
        this.clientFileStream = clientFileStream;
        this.length = length;
        this.data = new byte[this.length];
        this.data = data;
    }
    // </editor-fold> 
    // <editor-fold defaultstate="collapsed" desc="Methods">

    @Override
    public void run() {
        try {//Send the file!
            clientFileStream.sendBytes(data, length);
            clientFileStream.kill();
        } catch (IOException ex) {
            Logger.getLogger(ServerDataTransferThread.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    // </editor-fold> 
}